package cn.com.scitc.pano.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

@Controller
public class EditorController {
    public String edit;
    public String workname;

    @GetMapping("/edit")
    public String editxml(){
        return "edit";
    }
    @RequestMapping("/edit")
    @ResponseBody
    public String userwork(String edit) {
        this.edit = edit;
        return "edit";
    }
    @RequestMapping("/Page")
    @ResponseBody
    public String workname(String ids) {
        this.workname = ids;
        return "Page";
    }
    @GetMapping("/editor")
    public String editor(Model model){
        model.addAttribute("editorjs",workname +"/tour.js");
        model.addAttribute("editorxml",workname +"/tour.xml");
        return "editor";
    }
    @RequestMapping("/editxml")
    public String edit(Model model) throws IOException{
        File file = new File("D:/code/pano/src/main/resources/static" + workname +"/tour.xml");
        FileWriter fw = new FileWriter(file,false);
        fw.write(edit);
        fw.close();
        model.addAttribute("editmsg","修改成功");
        return "editmsg";
    }
    @GetMapping("/editmsg")
    public String editmsg(){
        return "editmsg";
    }
}
